package com.lovelc.cn;

import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPoolConfig;

import java.util.HashSet;
import java.util.Set;

/**
 * @ClassName JedisClusterTest
 * @Description TODO
 * @Author huangjh5
 * @Date 2021/1/12 22:45
 */
public class JedisClusterTest {
    public static void main(String[] args) {
        //构建连接
        JedisPoolConfig config = new JedisPoolConfig();
        Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
        jedisClusterNode.add(new HostAndPort("192.168.80.121", 7001));
        jedisClusterNode.add(new HostAndPort("192.168.80.121", 7002));
        jedisClusterNode.add(new HostAndPort("192.168.80.121", 7003));
        jedisClusterNode.add(new HostAndPort("192.168.80.121", 7004));
        jedisClusterNode.add(new HostAndPort("192.168.80.121", 7005));
        jedisClusterNode.add(new HostAndPort("192.168.80.121", 7006));
        JedisCluster jcd = new JedisCluster(jedisClusterNode, config);

        //设置数据 并且读取
        jcd.set("name:001","zhangfei");
        System.out.println(jcd.get("name:001"));

        //list
        jcd.del("list:001");
        jcd.lpush("list:001","0","hehe1","hehe2");
        System.out.println(jcd.lrange("list:001",0,-1));

    }
}
